home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / GENCTXT.ZIP / CHAP13.TXT < prev    next >
Text File  |  1987-11-21  |  6KB  |  191 lines

  1.  
  2.                  Chapter 13 - Character and Bit Manipulation
  3.  
  4.  
  5.                             UPPER AND LOWER CASE
  6.  
  7.              Load  and display the program UPLOW.C for an example of
  8.         a  program that does lots of character  manipulation.   More
  9.         specifically,  it changes the case of alphabetic  characters
  10.         around.   It illustrates the use of four functions that have
  11.         to  do with case.   It should be no problem for you to study
  12.         this program on your own and understand how it  works.   The
  13.         four functions on display in this program are all within the
  14.         user written function, "mix_up_the_chars".  Compile and  run
  15.         the  program  with  the  file  of  your  choice.   The  four
  16.         functions are;
  17.  
  18.              isupper();     Is the character upper case?
  19.              islower();     Is the character lower case?
  20.              toupper();     Make the character upper case.
  21.              tolower();     Make the character lower case.
  22.  
  23.              Many more Classification and Conversion routines should
  24.         be listed in the reference material for your compiler.
  25.  
  26.                         CLASSIFICATION OF CHARACTERS
  27.  
  28.              Load  and display the next program, CHARCLAS.C  for  an
  29.         example of character counting.  We have repeatedly used  the
  30.         backslash  n character representing a new line.   These  are
  31.         called escape sequences, and some of the more commonly  used
  32.         are defined in the following table;
  33.  
  34.              \n             Newline
  35.              \t             Tab
  36.              \b             Backspace
  37.              \"             Double quote
  38.              \\             Backslash
  39.              \0             NULL (zero)
  40.  
  41.              Consult your compiler documentation for a complete list
  42.         of escape sequences available with your compiler.
  43.  
  44.              By  preceding  each of the above  characters  with  the
  45.         backslash character, the character can be included in a line
  46.         of text for display,  or printing.   In the same way that it
  47.         is  perfectly  all right to use the letter "n" in a line  of
  48.         text as a part of someone's name, and as an end-of-line, the
  49.         other  characters can be used as parts of text or for  their
  50.         particular functions.
  51.  
  52.              The program on your screen uses the functions that  can
  53.         determine   the  class  of  a  character,   and  counts  the
  54.         characters  in  each class.   The number of  each  class  is
  55.  
  56.  
  57.  
  58.                                    Page 96
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.                  Chapter 13 - Character and Bit Manipulation
  69.  
  70.  
  71.         displayed  along with the line itself.   The three functions
  72.         are as follows;
  73.  
  74.              isalpha();     Is the character alphabetic?
  75.              isdigit();     Is the character a numeral?
  76.              isspace();     Is the character any of, \n, \t,
  77.                               or blank?
  78.  
  79.              As  noted above, many more Classification Routines  are
  80.         available with your compiler.
  81.  
  82.              This program should be simple for you to find your  way
  83.         through  so no explanation will be given.   It was necessary
  84.         to give an example with these functions used.   Compile  and
  85.         run this program with any file you choose.
  86.  
  87.                            THE LOGICAL FUNCTIONS
  88.  
  89.              Load and display the program BITOPS.C. The functions in
  90.         this  group of functions are used to do bitwise  operations,
  91.         meaning  that  the operations are performed on the  bits  as
  92.         though they were individual bits.   No carry from bit to bit
  93.         is performed as would be done with a binary addition.   Even
  94.         though  the operations are performed on a single bit  basis,
  95.         an entire byte or integer variable can be operated on in one
  96.         instruction.   The operators and the operations they perform
  97.         are given in the following table;
  98.  
  99.              &    Logical AND, if both bits are 1, the result is 1.
  100.              |    Logical OR, if either bit is one, the result is 1.
  101.              ^    Logical XOR,  (exclusive OR),  if one and only one
  102.                     bit is 1, the result is 1.
  103.              ~    Logical invert,  if the bit is 1, the result is 0,
  104.                     and if the bit is 0, the result is 1.
  105.  
  106.              The  example  program  uses  several  fields  that  are
  107.         combined  in each of the ways given above.   The data is  in
  108.         hexadecimal  format.   It  will be assumed that you  already
  109.         know hexadecimal format if you need to use these operations.
  110.         If  you  don't,  you  will need to study  it  on  your  own.
  111.         Teaching  the  hexadecimal format of numbers is  beyond  the
  112.         scope of this tutorial.
  113.  
  114.              Run the program and observe the output.
  115.  
  116.                            THE SHIFT INSTRUCTIONS
  117.  
  118.              The  last two operations to be covered in this  chapter
  119.         are  the left shift and the right shift instructions.   Load
  120.         the example program SHIFTER.C for an example using these two
  121.  
  122.  
  123.  
  124.                                    Page 97
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.                  Chapter 13 - Character and Bit Manipulation
  135.  
  136.  
  137.         instructions.    The   two  operations  use  the   following
  138.         operators;
  139.  
  140.              << n      Left shift n places.
  141.              >> n      Right shift n places.
  142.  
  143.              Once again the operations are carried out and displayed
  144.         using the hexadecimal format.   The program should be simple
  145.         for you to understand on your own, there is no tricky code.
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.                                    Page 98
  191.